﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SpeechBill
{
    public partial class Login : Form
    {
        public static string uname;
        String password;
        bool flagshow = false;//标记用户是否存在
        public Login()
        {
            InitializeComponent();
        }

        private void Login_Load(object sender, EventArgs e)
        {
            label1.BackColor = Color.Transparent;
            label2.BackColor = Color.Transparent;
            label3.BackColor = Color.Transparent;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection con = DBHelper.GetCon();

            con.Open();
            String cmdText = "select * from userlogin where username = '" + textBox1.Text + "'";
            SqlCommand cmd = new SqlCommand(cmdText, con);

            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                password = reader["password"].ToString();
                if (password.Trim() == textBox2.Text.ToString())
                {
                    flagshow = true;
                    uname = textBox1.Text.ToString();
                    CurrentPosition curpos = new CurrentPosition();
                    curpos.GetLocationEvent();
                }
            }
            reader.Close();

            con.Close();
            if (flagshow == true)
            {
                showMainForm();

            }
            else
            {
                MessageBox.Show("用户不存在或密码错误！", "提示");
                return;
            }
        }
        void showMainForm()
        {
            ////this.Close();
            //Main mn = new Main();
            //mn.Show();
            DialogResult = DialogResult.OK;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Register reg = new Register();
            reg.ShowDialog();
        }
    }
}
